package o;

import android.content.Context;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.Session;
import android.content.pm.PackageInstaller.SessionInfo;
import java.io.IOException;
import java.util.List;

public class dqj extends dpn<Boolean, Boolean> {
    protected /* synthetic */ Object ˋ(Context context, Object obj) throws InterruptedException {
        return ॱ(context, (Boolean) obj);
    }

    protected /* synthetic */ void ˏ(Context context, Object obj, Object obj2) throws InterruptedException {
        ˋ(context, (Boolean) obj, (Boolean) obj2);
    }

    protected /* synthetic */ Object ॱ(Context context) throws InterruptedException {
        return ˋ(context);
    }

    public dqj() {
        this.ˊ = "UselessPreApkTask";
    }

    protected Boolean ˋ(Context context) {
        long ॱ = euf.ˎ().ॱ("predownloadapkcheckmanagermenttime", 0);
        if (System.currentTimeMillis() - ॱ > 259200000) {
            Logger.ˎ(this.ˊ, "managerPreDownloadApkBegin now:" + System.currentTimeMillis() + ",lastTime:" + ॱ);
            return Boolean.valueOf(true);
        }
        Logger.ˎ(this.ˊ, "managerPreDownloadApk not fit the time!!!! now:" + System.currentTimeMillis() + ",lastTime:" + ॱ);
        return Boolean.valueOf(false);
    }

    protected Boolean ॱ(Context context, Boolean bool) {
        if (bool == null || !bool.booleanValue()) {
            return Boolean.valueOf(false);
        }
        Logger.ˏ("ScheduleRepeatService", this.ˊ + " execute");
        new dpo().ˋ();
        if (((ceq) cdb.ॱ(ceq.class)).ॱ() == 0) {
            ˏ(ContentManager.getInstant().getContext());
        }
        return Boolean.valueOf(true);
    }

    protected void ˋ(Context context, Boolean bool, Boolean bool2) {
        if (bool2 != null && bool2.booleanValue()) {
            euf.ˎ().ˎ("predownloadapkcheckmanagermenttime", System.currentTimeMillis());
        }
    }

    private void ˏ(Context context) {
        PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
        List mySessions;
        try {
            mySessions = packageInstaller.getMySessions();
        } catch (Exception e) {
            Logger.ˋ(this.ˊ, "getMySessions failed");
            mySessions = null;
        }
        if (r0 != null && !r0.isEmpty()) {
            Logger.ˋ(this.ˊ, "have expired Sessions:" + r0.size());
            for (SessionInfo sessionInfo : r0) {
                if (sessionInfo != null) {
                    Session session = null;
                    try {
                        Session openSession = packageInstaller.openSession(sessionInfo.getSessionId());
                        if (openSession != null) {
                            try {
                                openSession.abandon();
                            } catch (Exception e2) {
                                Logger.e(this.ˊ, "abandon failed" + e2.getMessage());
                            }
                        }
                    } catch (IOException e3) {
                        Logger.e(this.ˊ, "openSession failed.");
                        if (null != null) {
                            try {
                                session.abandon();
                            } catch (Exception e22) {
                                Logger.e(this.ˊ, "abandon failed" + e22.getMessage());
                            }
                        }
                    } catch (SecurityException e4) {
                        Logger.e(this.ˊ, "openSession failed SecurityException.");
                        if (null != null) {
                            try {
                                session.abandon();
                            } catch (Exception e222) {
                                Logger.e(this.ˊ, "abandon failed" + e222.getMessage());
                            }
                        }
                    } catch (Exception e5) {
                        Logger.e(this.ˊ, "openSession failed SecurityException.");
                        if (null != null) {
                            try {
                                session.abandon();
                            } catch (Exception e2222) {
                                Logger.e(this.ˊ, "abandon failed" + e2222.getMessage());
                            }
                        }
                    } catch (Throwable th) {
                        if (null != null) {
                            try {
                                session.abandon();
                            } catch (Exception e6) {
                                Logger.e(this.ˊ, "abandon failed" + e6.getMessage());
                            }
                        }
                    }
                }
            }
        }
    }
}
